package cz.data.common.support.metadata;

import cz.data.common.support.DataTypeEnum;

public enum MysqlDataTypeEnum implements DataTypeEnum {

    VARCHAR("varchar", "变长字符串"),
    TEXT("text", "长文本"),
    INT("int", "int整型"),
    TINYINT("tinyint", "tinyint整型"),
    BIGINT("bigint", "bigint整型"),
    FLOAT("float", "单精度小数"),
    DOUBLE("double", "双精度小数"),
    DECIMAL("decimal", "定点数"),
    CHAR("char", "定长字符串"),
    DATE("date", "date日期"),
    TIME("time", "time时间"),
    YEAR("year", "year年"),
    DATETIME("datetime", "日期时间"),
    TIMESTAMP("timestamp", "时间戳"),
    BLOB("blob", "二进制");

    private final String value;
    private final String title;

    MysqlDataTypeEnum(String value, String title) {
        this.value = value;
        this.title = title;
    }

    public String getValue() {
        return value;
    }

    public String getTitle() {
        return title;
    }

    public static MysqlDataTypeEnum match(String value, MysqlDataTypeEnum defaultItem) {
        if (value != null) {
            for (MysqlDataTypeEnum item : MysqlDataTypeEnum.values()) {
                if (item.getValue().equalsIgnoreCase(value)) {
                    return item;
                }
            }
        }
        return defaultItem;
    }
}
